package com.stylefeng.guns.core.util;

import java.util.Date;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;

public class JsonUtil {

    private static SerializeConfig mapping = new SerializeConfig();

    /**
     * 默认的处理时间
     * 
     * @param jsonText
     * @return
     */
    public static String toJSON(Object object) {
        return JSON.toJSONString(object, SerializerFeature.WriteDateUseDateFormat);
    }

    /**
     * 自定义时间格式
     * 
     * @param jsonText
     * @return
     */
    public static String toJSON(String dateFormat, Object object) {
        mapping.put(Date.class, new SimpleDateFormatSerializer(dateFormat));
        return JSON.toJSONString(object, mapping);
    }
}
